# Contributor: LI Xuzhang <lixuzhang@gmail.com>
# Contributor: Stas Elensky <stas-at-flexsys-dot-com-dot-ua>

_realname=libmodbus
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=782.ebc4f47
_commit=ebc4f4788678eda8d99e23be87c61a662a9d26b7
pkgrel=1
pkgdesc="A Modbus library for Linux, Mac OS X, FreeBSD, QNX and Win32 (mingw-w64)"
url="https://libmodbus.org/"
msys2_references=(
  "cpe: cpe:/a:libmodbus:libmodbus"
)
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-asciidoc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "git")
options=('!buildflags' '!emptydirs')
source=("${_realname}::git+https://github.com/stephane/libmodbus#commit=$_commit")
sha256sums=('SKIP')

pkgver() {
  cd ${_realname}
  echo $(git rev-list --count $_commit).$(git rev-parse --short $_commit)
  #git describe --tags |sed 's+-+.+g'
}

prepare() {
  cd ${_realname}
  ./autogen.sh
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

package() {
  cd build-${MSYSTEM}
  make DESTDIR="${pkgdir}" install
}
